<div class="container">
    <div class="page-header">
        <h1>{if $id}Редактирование{else}Добавление{/if} баннера</h1>
    </div>
    <form action="{$cururl}" method="post" class="form-horizontal" enctype="multipart/form-data">
    <div class="row">
        <div class="span6">
        	<fieldset>
        	    <div class="control-group{if $errors.title} error{/if}">
                    <label class="control-label">Название</label>
                    <div class="controls">
                        <input type="text" name="title" value="{$aData.title}">
                        <p class="help-block{if !$errors.title} invisible{/if}">{$errors.title|default:'&nbsp;'}</p>
                    </div>
                </div>
                <div class="control-group{if $errors.url} error{/if}">
                    <label class="control-label">URL</label>
                    <div class="controls">
                        <input type="text" name="url" value="{$aData.url}">
                        <p class="help-block{if !$errors.url} invisible{/if}">{$errors.url|default:'&nbsp;'}</p>
                    </div>
                </div>
                <div class="control-group{if $errors.code_block} error{/if}">
                    <label class="control-label">Код</label>
                    <div class="controls">
                        <textarea name="code_block">{$aData.code_block|escape}</textarea>
                        <p class="help-block{if !$errors.code_block} invisible{/if}">{$errors.code_block|default:'&nbsp;'}</p>
                    </div>
                </div>
                <div class="control-group{if $errors.width} error{/if}">
                    <label class="control-label">Ширина</label>
                    <div class="controls">
                        <input type="text" name="width" value="{$aData.width}">
                        <label class="checkbox">
                            <input type="hidden" name="width_in_percents" value="0">
                            <input type="checkbox" name="width_in_percents" value="1"> В процентах
                        </label>
                        <p class="help-block{if !$errors.width} invisible{/if}">{$errors.width|default:'&nbsp;'}</p>
                    </div>   
                </div>
                <div class="control-group{if $errors.height} error{/if}">
                    <label class="control-label">Высота</label>
                    <div class="controls">
                        <input type="text" name="height" value="{$aData.height}">
                        <label class="checkbox">
                            <input type="hidden" name="height_in_percents" value="0">
                            <input type="checkbox" name="height_in_percents" value="1"> В процентах
                        </label>
                        <p class="help-block{if !$errors.height} invisible{/if}">{$errors.height|default:'&nbsp;'}</p>
                    </div>
                </div>
                <div class="control-group{if $errors.start_date} error{/if}">
                    <label class="control-label">Дата начала</label>
                    <div class="controls">
                        <input type="text" name="start_date" id="start_date" value="{$aData.start_date}">
                        <p class="help-block{if !$errors.start_date} invisible{/if}">{$errors.start_date|default:'&nbsp;'}</p>
                    </div>
                </div>
                <div class="control-group{if $errors.end_date} error{/if}">
                    <label class="control-label">Дата окончания</label>
                    <div class="controls">
                        <input type="text" name="end_date" id="end_date" value="{$aData.end_date}">
                        <p class="help-block{if !$errors.end_date} invisible{/if}">{$errors.end_date|default:'&nbsp;'}</p>
                    </div>
                </div>
                <div class="control-group{if $errors.clicks_limit} error{/if}">
                    <label class="control-label">Лимит кликов</label>
                    <div class="controls">
                        <input type="text" name="clicks_limit" value="{$aData.clicks_limit|default:'0'}">
                        <p class="help-block{if !$errors.clicks_limit} invisible{/if}">{$errors.clicks_limit|default:'&nbsp;'}</p>
                    </div>
                </div>
                <div class="control-group{if $errors.views_limit} error{/if}">
                    <label class="control-label">Лимит показов</label>
                    <div class="controls">
                        <input type="text" name="views_limit" value="{$aData.views_limit|default:'0'}">
                        <p class="help-block{if !$errors.views_limit} invisible{/if}">{$errors.views_limit|default:'&nbsp;'}</p>
                    </div>
                </div>
                <div class="control-group{if $errors.daily_clicks_limit} error{/if}">
                    <label class="control-label">Дн. лимит кликов</label>
                    <div class="controls">
                        <input type="text" name="daily_clicks_limit" value="{$aData.daily_clicks_limit|default:'0'}">
                        <p class="help-block{if !$errors.daily_clicks_limit} invisible{/if}">{$errors.daily_clicks_limit|default:'&nbsp;'}</p>
                    </div>
                </div>
                <div class="control-group{if $errors.daily_views_limit} error{/if}">
                    <label class="control-label">Дн. лимит показов</label>
                    <div class="controls">
                        <input type="text" name="daily_views_limit" value="{$aData.daily_views_limit|default:'0'}">
                        <p class="help-block{if !$errors.daily_views_limit} invisible{/if}">{$errors.daily_views_limit|default:'&nbsp;'}</p>
                    </div>
                </div>
                <div class="control-group{if $errors.client_id} error{/if}">
                    <label class="control-label">Клиент</label>
                    <div class="controls">
                        <select name="client_id">
                            <option value="0">-- Выберите --</option>
                            {foreach from=$aClients item=item}
                            <option value="{$item.id}"{if $aData.client_id == $item.id} selected{/if}>{$item.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
        	</fieldset>
        </div>
        {if $id}{include file="manager/banner/edit_update.tpl"}{else}{include file="manager/banner/edit_create.tpl"}{/if}
    </div>
    <div class="row">
        <div class="form-actions">
            <button class="btn btn-success" type="submit"><i class="icon-check icon-white"></i> Сохранить</button>
        </div>
    </div>
    </form>
</div>

<div id="media_container" class="hidden">
    <div class="alert alert-info">
        <a class="close" data-dismiss="alert">x</a>
        <div class="control-group">
            <label class="control-label">Изображение</label>
            <div class="controls">
                <input type="file" name="image[]" class="input-file">
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Flash</label>
            <div class="controls">
                <input type="file" name="flash[]" class="input-file">
            </div>
        </div>
    </div>
</div>

{literal}
<script type="text/javascript">

$('#start_date').datetimepicker({
    onClose: function(dateText, inst) {
        var endDateTextBox = $('#end_date');
        if (endDateTextBox.val() != '') {
            var testStartDate = new Date(dateText);
            var testEndDate = new Date(endDateTextBox.val());
            if (testStartDate > testEndDate)
                endDateTextBox.val(dateText);
        }
        else {
            endDateTextBox.val(dateText);
        }
    },
    onSelect: function (selectedDateTime){
        var start = $(this).datetimepicker('getDate');
        $('#end_date').datetimepicker('option', 'minDate', new Date(start.getTime()));
    }
});
$('#end_date').datetimepicker({
    onClose: function(dateText, inst) {
        var startDateTextBox = $('#start_date');
        if (startDateTextBox.val() != '') {
            var testStartDate = new Date(startDateTextBox.val());
            var testEndDate = new Date(dateText);
            if (testStartDate > testEndDate)
                startDateTextBox.val(dateText);
        }
        else {
            startDateTextBox.val(dateText);
        }
    },
    onSelect: function (selectedDateTime){
        var end = $(this).datetimepicker('getDate');
        $('#start_date').datetimepicker('option', 'maxDate', new Date(end.getTime()));
    }
});

</script>
{/literal}